<?php

namespace App\Models;

use App\Constants\UserFilterType;
use Illuminate\Database\Eloquent\Model;

class Activity extends Model
{
    protected $table = 'activities';
    public $fillable = [
        'name','start_time','end_time','banner',
        'rules','purpose','filter_type','ignores','rewards'
    ];

    public function targets() {
        $str_Class = '';
        if ($this->filter_type == UserFilterType::CHANNEL) {
            $str_Class = Channel::class;
        }else if($this->filter_type == UserFilterType::USER_GROUP){
            $str_Class = UserGroup::class;
        }
        return $this->belongsToMany($str_Class,'activity_user_filters','activity_id','filter_id');
    }

    public function channels(){
        return $this->belongsToMany(Channel::class,'activity_user_filters','activity_id','filter_id');
    }

    public function groups(){
        return $this->belongsToMany(UserGroup::class,'activity_user_filters','activity_id','filter_id');
    }

    public function packages(){
        return $this->belongsToMany(RewardPackage::class,'activity_rewards','activity_id','package_id');
    }
}
